﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.QingJia;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.QingJia
{
    public class QingjiaDelCommandHandler : IRequestHandler<QingjiaDelCommand, APIResult<object>>
    {
        private readonly IBaseRepository<LeaveApplicationForm> lRepo;
        private readonly IMapper mapper;

        public QingjiaDelCommandHandler(IBaseRepository<LeaveApplicationForm>lRepo,IMapper mapper)
        {
            this.lRepo = lRepo;
            this.mapper = mapper;
        }


        public async Task<APIResult<object>> Handle(QingjiaDelCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
           
            var model  = lRepo.GetAll().Result.Where(x=>x.FormId == request.FormId).FirstOrDefault();
            if (model != null)
            {
                model.IsDeleted = true;
                await lRepo.Update(model);
                result.Code = APIEnum.删除成功;
                result.Msg = APIEnum.删除成功.ToString();
            }
         else
            {
                result.Code = APIEnum.删除失败;
                result.Msg = APIEnum.删除失败.ToString();
            }
            return await Task.FromResult(result);   






        }
    }
}
